import instance from "../request"
import type { Ref } from "vue"
/**
 * 商品分类请求
*/
interface IProductCateList {
    description: string,
    icon: string,
    id: number,
    keywords: string,
    level: number,
    name: string,
    navStatus: number,
    parentId: number,
    productCount: number,
    productUnit: string,
    showStatus: number,
    sort: number
}
interface IProductCateListRes {
    list: IProductCateList[],
    code: number,
    pageNum: number,
    pageSize: number,
    total: number,
    totalPage: number,
    message: string
}
interface IProductCateListParams {
    parentId: Ref<number>,
    pageNum?: number,
    pageSize?: number
}

let productCateList = (data?: IProductCateListParams): Promise<IProductCateListRes> => {
    let obj = { ...data }
    if (obj.parentId) {
        delete obj.parentId
    }
    return instance.get(`productCategory/list/${data?.parentId}`, { params:{
        pageNum: 1,
        pageSize: 100
    } })
}
/**
 * 导航栏更改请求
 * */
interface updateNavStatusParams {
    ids: number,
    navStatus: number
}
let updateNavStatus = (form: updateNavStatusParams) => {
    return instance.post('productCategory/update/navStatus', form)
}
/**
 * 是否显示更改请求
 * */
interface updateShowStatusParams {
    ids: number,
    showStatus: number
}
let updateShowStatus = (form: updateShowStatusParams) => {
    return instance.post('productCategory/update/showStatus', form)
}
/** 
 * 删除商品分类的请求
*/
let deleteCate = (id: number) => {
    return instance.post(`productCategory/delete/${id}`)
}
/**
 *根据id获取商品分类
*/
let productCategoryItem = (id: number) => {
    return instance.get(`productCategory/${id}`)
}
/**
 * 获取编辑页中的筛选属性
*/
let productCategoryWithAttr = () => {
    return instance.get('productAttribute/category/list/withAttr')
}






/**
 * 编辑商品分类的请求
*/
interface IProductCatUpdateParams {
    id: number,
    description?: string,
    icon?: string,
    keywords?: string,
    name: string,
    navStatus?: number,
    parentId?: number,
    productAttributeIdList?: [],
    productUnit?: string,
    showStatus?: number,
    sort?: number
}
let productCatUpdate = (data: IProductCatUpdateParams) => {
    return instance.post(`productCategory/update/${data.id}`, { data })
}
































/**
 * 商品类型请求
*/
interface IProductCateAttrList {
    attributeCount: number,
    id: number,
    name: string,
    paramCount: number
}
interface IProductCateAttrListRes {
    code: number,
    list: IProductCateAttrList[],
    pageNum: number,
    pageSize: number,
    total: number,
    totalPage: number,
    message: string
}
interface IProductCateAttrListParams {
    pageNum?: number,
    pageSize?: number,
}

let productCateAttrList = (data?: IProductCateAttrListParams): Promise<IProductCateAttrListRes> => {
    return instance.get('productAttribute/category/list', { params: data })
}
/**
 * 填加商品类型请求
*/
interface IProductCateAttrCreateParams {
    name: string
}
let productCateAttrCreate = (data: IProductCateAttrCreateParams) => {
    return instance.post('productAttribute/category/create', data)
}
/**
 * 删除商品类型的请求
*/
interface IProductCateAttrDeleteParams {
    id: number
}
let productCateAttrDelete = (data: IProductCateAttrDeleteParams) => {
    return instance.get(`productAttribute/category/delete/${data.id}`, { params: data })
}
/**
 * 编辑商品类型的请求
*/
interface IProductCateAttrUpdateParams {
    id: number,
    name: string
}
let productCateAttrUpdate = (data: IProductCateAttrUpdateParams) => {
    let formData = new FormData()
    formData.append('name', data.name)
    return instance.post(`productAttribute/category/update/${data.id}`, formData)
}
/**
 * 查询属性列表
*/
interface productAttributeListParams {
    id?: number,
    pageNum?: number,
    pageSize?: number,
    type?: 0
}
let productAttributeList = (data: productAttributeListParams) => {
    return instance.get(`productAttribute/list/${data.id}?type=0`, {
        params: data
    })
}
/**
 * 查询参数列表
*/
interface productAttributeList2Params {
    id: number,
    pageNum?: number,
    pageSize?: number,
    type: 1
}
let productAttributeList2 = (data: productAttributeList2Params) => {
    return instance.get(`productAttribute/list/${data.id}?type=1`, {
        params: data
    })
}
/**
 * 批量删除商品属性
*/
interface productAttrDeleteParams {
    ids: number[]
}
let productAttrDelete = (data: productAttrDeleteParams) => {
    return instance.post(`productAttribute/delete`, data)
}
/**
 * 新增商品属性
*/
interface productAttributeCreateParams {
    filterType: number,
    handAddStatus: number,
    inputList: string,
    inputType: number,
    name: string,
    productAttributeCategoryId: number,
    relatedStatus: number,
    searchType: number,
    selectType: number,
    sort: number,
    type: number
}
let productAttributeCreate = (data: productAttributeCreateParams) => {
    return instance.post('productAttribute/create', data)
}






























/**
 * 品牌管理请求
*/
interface IBrandList {
    bigPic?: string,
    brandStory?: string,
    factoryStatus?: number,
    firstLetter?: string,
    id?: number,
    logo?: string,
    name?: string,
    productCommentCount?: number,
    productCount?: number,
    showStatus?: number,
    sort?: number
}
interface IBrandListRes {
    code: number,
    list: IBrandList[]
    pageNum: number,
    pageSize: number,
    total: number,
    totalPage: number
    message: string
}

interface IBrandParams {
    pageNum?: number,
    pageSize?: number,
}

let BrandList = (data?: IBrandParams): Promise<IBrandListRes> => {
    return instance.get('brand/list', { params: data })
}
/**
 * 品牌制造商更改请求
 * */
interface updateFactoryStatusParams {
    ids: number,
    factoryStatus: number
}
let updateFactoryStatus = (form: updateFactoryStatusParams) => {
    return instance.post('brand/update/factoryStatus', form)
}
/**
 * 品牌显示更改请求
 * */
interface updateBrandShowStatusParams {
    ids: number,
    showStatus: number
}
let updateBrandShowStatus = (form: updateBrandShowStatusParams) => {
    return instance.post('brand/update/showStatus', form)
}
/**
 * 品牌搜索请求
*/
interface IBrandSearchListParams {
    keyword?: string,
    pageNum?: number,
    pageSize?: number,
}
let brandSearchList = (form: IBrandSearchListParams) => {
    return instance.get(`brand/list`, {
        params: form
    })
}
/**
 * 根据编号查询品牌信息
*/
let brandItemDetail = (id: number) => {
    return instance.get(`brand/${id}`)
}

/**
 * 更新品牌
*/
interface brandUpdateParams {
    bigPic: string,
    brandStory: string,
    factoryStatus: number,
    firstLetter: string,
    id: string,
    logo: string,
    name: string,
    productCommentCount: string,
    productCount: string,
    showStatus: number,
    sort: string,
}
let brandUpdate = (data: brandUpdateParams) => {
    return instance.post(`brand/update/${data.id}`, data)
}










export {
    productCateList, productCateAttrList,
    BrandList,
    updateNavStatus,
    updateShowStatus,
    deleteCate,
    productCatUpdate,
    updateFactoryStatus,
    updateBrandShowStatus,
    brandSearchList,
    productCateAttrCreate,
    productCateAttrDelete,
    productCateAttrUpdate,
    productCategoryItem,
    productCategoryWithAttr,
    brandItemDetail,
    productAttributeList,
    productAttributeList2,
    productAttrDelete,
    productAttributeCreate,
    brandUpdate

}
export type { IBrandList }